home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1998 November / Freeware November 1998.img / dist / fw_UDELxntp.idb / usr / freeware / src / xntp-3.4o-export / lib / tvtoa.c.z / tvtoa.c
C/C++ Source or Header  |  1998-01-21  |  557b  |  34 lines

  1. /*
  2.  * tvtoa - return an asciized representation of a struct timeval
  3.  */
  4. #include <stdio.h>
  5. #include <sys/time.h>
  6.  
  7. #include "lib_strbuf.h"
  8. #include "ntp_stdlib.h"
  9.  
  10. char *
  11. tvtoa(tv)
  12.     struct timeval *tv;
  13. {
  14.     register char *buf;
  15.     register u_long sec;
  16.     register u_long usec;
  17.     register int isneg;
  18.  
  19.     if (tv->tv_sec < 0 || tv->tv_usec < 0) {
  20.         sec = -tv->tv_sec;
  21.         usec = -tv->tv_usec;
  22.         isneg = 1;
  23.     } else {
  24.         sec = tv->tv_sec;
  25.         usec = tv->tv_usec;
  26.         isneg = 0;
  27.     }
  28.  
  29.     LIB_GETBUF(buf);
  30.  
  31.     (void) sprintf(buf, "%s%lu.%06lu", (isneg?"-":""), sec, usec);
  32.     return buf;
  33. }
  34.